SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE FUNCTION [Live].[GetComplianceChangeReason]
    (
     @IssuerId INT, @ExportId INT
    )
RETURNS VARCHAR(50)
AS
    BEGIN
		DECLARE @return VARCHAR(100)
--DECLARE @ExportId INT = (SELECT MAX(e.ExportId) FROM FSFundModel_VALCOMM.Reporting.Export e WHERE e.FundId ='FSIC')
--DECLARE @AssetIntrnlId INT = 55

--DECLARE @IssuerId INT
DECLARE  @MktVal DECIMAL(38,10)
DECLARE @Ticker VARCHAR(20)
DECLARE @IssuerName VARCHAR(100)
--DECLARE @Spread DECIMAL(38,10)
--DECLARE @Pik DECIMAL(38,10)
--DECLARE @PctCostDiscPurchPrc DECIMAL(38,10)





SELECT @MktVal = fi.MktVal, @Ticker = iss.Ticker, @IssuerName = iss.IssuerName
		    FROM FSFundModel.Reporting.FundIssuer fi 
				INNER JOIN  FSFundModel.Reporting.Issuer iss
				ON fi.ExportId = iss.ExportId 
				AND fi.IssuerId = iss.IssuerId
			WHERE 
			fi.ExportId = @ExportId 
			AND fi.IssuerId = @IssuerId
			
IF @MktVal = 0 
	BEGIN
		SET @return = 'Company Removed From Portfolio'
	END

ELSE 
	BEGIN
		SET @return = 'New Portfolio Company'
	END

		
IF @Ticker = 0
	BEGIN
		SET @return = 'Company Removed From Portfolio'
	END

ELSE 
	BEGIN
		SET @return = 'New Portfolio Company'
	END

--IF @FinType = 'Debt' 
--		BEGIN
--			IF @FixedRate = 0
--				BEGIN
--					SET @return = 
--						CASE 
--							WHEN @BaseRateType LIKE 'EURIBOR%' THEN 'EURIBOR+' +cast(CAST(@Spread*10000 AS INT)AS varchar(50))
--							WHEN @BaseRateType LIKE 'PRIME%' THEN 'Prime+'+cast(CAST(@Spread*10000 AS INT) AS varchar(50))
--							ELSE 'L+' + cast(CAST(@Spread*10000 AS INT) AS varchar(50))
--						END		
--				END
--			ELSE 
--				BEGIN
--					SET @return = CAST(CAST(@FixedRate * 100 AS DECIMAL(38,1)) AS  varchar(50)) + '%'
--				END 	
--		END
--   ELSE 
--   BEGIN
--		IF @InsDefId = 8 
--			BEGIN
--				SET @return = CAST(CAST(@PctCostDiscPurchPrc * 100 AS DECIMAL(38,1)) AS  varchar(50)) + '%'
--			END	
--	END

--	IF @Pik <> 0  SET @return = @return + ', ' + CAST(CAST(@Pik*100 AS DECIMAL(38,1)) AS varchar(50)) + '% PIK'




		RETURN @return 
    END

GO
EXEC sp_addextendedproperty N'VirtualFolder', N'Live', 'SCHEMA', N'Live', 'FUNCTION', N'GetComplianceChangeReason', NULL, NULL
GO
